<script lang="ts" setup>
import { getRodListAPI } from '@/apis/rod';
import { onMounted, ref } from 'vue';
import type { rod, rodListParams } from '@/types/rod';

const params = ref<rodListParams>({
  // 当前页面的页码
  page: 1,
  // 每页显示的条数
  pageSize: 10,
});

const rodList = ref<rod[]>([]);
const total = ref(0);

const getRodList = async () => {
  const res = await getRodListAPI(params.value);
  // console.log('一体杆列表', res.data.rows)
  rodList.value = res.data.rows;
  total.value = res.data.total;
};

onMounted(() => {
  getRodList();
});
</script>

<template>
  <div class="card-container">
    <!-- 搜索区域 -->
    <div class="search-container">
      <span class="search-label">一体杆名称：</span>
      <el-input
        v-model="params.poleName"
        clearable
        placeholder="请输入名称"
        class="search-main"
      />
      <span class="search-label">一体杆编号：</span>
      <el-input
        v-model="params.poleNumber"
        clearable
        placeholder="请输入编号"
        class="search-main"
      />
      <span class="search-label">运行状态：</span>
      <el-select v-model="params.poleStatus" style="width: 240px">
        <el-option label="正常" value="0" />
        <el-option label="故障" value="1" />
      </el-select>
      <el-button type="primary" class="search-btn">查询</el-button>
    </div>
    <!-- 新增删除操作区域 -->
    <div class="create-container">
      <el-button type="primary">添加一体杆</el-button>
      <el-button>批量删除</el-button>
    </div>
    <!-- 表格区域 -->
    <div class="table">
      <el-table style="width: 100%" :data="rodList">
        <el-table-column type="index" label="序号" />
        <el-table-column label="一体杆名称" prop="poleName" />
        <el-table-column label="一体杆编号" prop="poleNumber" />
        <el-table-column label="一体杆IP" prop="poleIp" />
        <el-table-column label="安装区域" prop="areaName" />
        <el-table-column label="一体杆类型" prop="poleType">
          <template #default="{ row }">
            <el-tag v-if="row.poleType === 'center'" type="warning"
              >中心杆</el-tag
            >
            <el-tag v-if="row.poleType === 'entrance'" type="success"
              >入口杆</el-tag
            >
            <el-tag v-if="row.poleType === 'export'" type="danger"
              >出口杆</el-tag
            >
          </template>
        </el-table-column>
        <el-table-column label="操作" fixed="right" width="180">
          <template>
            <el-button size="small" type="text">续费</el-button>
            <el-button size="small" type="text">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <!-- 分页 -->
    <div class="page-container">
      <el-pagination
        layout="total,sizes, prev, pager, next,jumper"
        :total="total"
        :page-sizes="[5, 10, 15, 20, 25, 30, 50]"
        v-model:page-size="params.pageSize"
        v-model:current-page="params.page"
        @change="getRodList"
      />
      <!-- 
      @change=""  : 将下面的两个效果进行了整合，具有两个的功能
      @size-change=""
      @current-change=""
      -->
    </div>
  </div>
</template>

<style lang="scss" scoped>
.card-container {
  padding: 20px;
  background-color: #fff;
}

.search-container {
  display: flex;
  align-items: center;
  border-bottom: 1px solid rgb(237, 237, 237, 0.9);
  padding-bottom: 20px;

  .search-main {
    width: 220px;
    margin-right: 10px;
  }

  .search-btn {
    margin-left: 20px;
  }
}

.create-container {
  margin: 10px 0px;
}

.page-container {
  padding: 4px 0px;
  text-align: right;
  display: flex;
  justify-content: flex-end;
}

.form-container {
  padding: 0px 80px;
}
</style>
